<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="/WEB-INF/tlds/c.tld"%>
<%@ taglib prefix="spring" uri="/WEB-INF/tlds/spring.tld"%>
<c:set var="BasePath" value="${pageContext.request.contextPath}"></c:set>
<c:set var="Plugins" value="${pageContext.request.contextPath}/res/plugins"></c:set>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>商品库存</title>

<link href="${Plugins}/ligerUI/skins/Aqua/css/ligerui-all.css" rel="stylesheet" type="text/css" />
<link href="${Plugins}/ligerUI/skins/ligerui-icons.css" rel="stylesheet" type="text/css" />
<script src="${Plugins}/jquery/jquery-1.8.0.min.js"	type="text/javascript"></script>
<script src="${Plugins}/ligerUI/js/ligerui.min.js" type="text/javascript"></script>
<script src="${BasePath}/res/js/ligerCommon.js"></script>
<script src="${Plugins}/datepicker/WdatePicker.js" type="text/javascript"></script>
<script src="${BasePath}/res/js/common/ajaxfileupload.js" type="text/javascript"></script>

<style type="text/css">
#searchbar{
   		margin-bottom: 10px;
   		margin-left:15px;
  }
  .navbar {
		height: 20px;
		border-bottom: #E6E6E6 solid 1px;
		line-height: 20px;
	}
  .l-button-search {
		width: 50px;
		margin-left: 10px;
		padding-bottom: 2px;
		display: inline;
}
</style>
</head>

<body style="padding:6px; overflow:hidden;">
<div class="navbar">
		<span>您当前的位置：</span>
		商品管理 &gt; 商品库存&gt; 设置vip预占数
</div><br>
	<form name="form1" method="post" action="setVipOccupyQuantity.do" id="form1">
		<table cellpadding="0" cellspacing="0" class="l-table-edit p-tab" width="100%">
			<tr height="30px">
				<td align="left" class="l-table-edit-td s-lab"><font
					color="red">*</font>良品总数量：</td>
				<td align="left" class="l-table-edit-td s-lab">
					${productStock.qualifiedQuantity}
				</td>
			</tr>
			<tr height="30px">
				<td align="left" class="l-table-edit-td s-lab"><font
					color="red">*</font>vip预占最大数量：</td>
				<td align="left" class="l-table-edit-td s-lab">
					${(productStock.qualifiedQuantity - productStock.preOccupyQuantity + productStock.vipOccupyQuantity)}
				</td>
			</tr>
			<tr height="30px">
				<td align="left" class="l-table-edit-td s-lab"><font
					color="red">*</font>vip预占数：
				</td>
				<td align="left" class="l-table-edit-td ">
					<input name="id" id="id" value="${productStock.id}" type="hidden"/>
					<input id="usefulQuantity" value="${(productStock.qualifiedQuantity - productStock.preOccupyQuantity + productStock.vipOccupyQuantity)}" type="hidden"/>
					<input name="vipOccupyQuantity"  id="vipOccupyQuantity" value="${productStock.vipOccupyQuantity}" />
				</td>
			</tr>
			
			<tr height="30px">
				<td colspan="2" >
					<input type="button" onclick="setVipOccupyQuantity()" value="确认" id="submit1" style="font-size: 12px;" class="l-button l-button-submit"/>
				</td>
			</tr>
		</table>
	</form>
	<script>
	var basePath ="${BasePath}";

	function setVipOccupyQuantity(){
		var vipOccupyQuantity = parseInt( $('#vipOccupyQuantity').val());
		var usefulQuantity = parseInt( $('#usefulQuantity').val());
		if(vailData(usefulQuantity,vipOccupyQuantity)){
			$.ajax({
				type : 'post',
				dataType : 'text',
				data : {
					vipOccupyQuantity : vipOccupyQuantity,
					id : $('#id').val()
				},
				url : "setVipOccupyQuantity.do",
				success : function(data) {
					if (data == 'fail') {
						window.parent.parent.f_tip('设置失败');
					} else {
						window.parent.parent.f_tip('设置成功');
						//window.parent.$.ligerDialog.close();
						//window.parent.$(".l-dialog,.l-window-mask").remove();
						window.parent.location.reload();
					}
				}
			});
		}
	}
	
	function vailData(usefulQuantity,vipOccupyQuantity){
		if(vipOccupyQuantity > usefulQuantity){
			window.parent.parent.f_tip('vip占用数量必须小于或等于最大设置数量');
			return false;
		}else if(vipOccupyQuantity < 0){
			window.parent.parent.f_tip('vip占用数量必须大于或等于0');
			return false;
		}else if('${productStock.vipOccupyQuantity}' == vipOccupyQuantity){
			window.parent.parent.f_tip('设置成功');
			window.parent.location.reload();
			return false;
		}
		return true;
	}
    </script>
</body>
</html>

